package hulppakket;

import java.awt.Color;
import java.io.Serializable;

public class Color3f extends Tuple3f implements Serializable {

	private static final long serialVersionUID = 2475794013554934553L;

	/**
	 * Constructs and initializes a Color3f to (0.0, 0.0, 0.0).
	 */
	public Color3f() {
	}

	/**
	 * Constructs and initializes a Color3f from the specified AWT Color object.
	 * 
	 * @param c
	 */
	public Color3f(Color c) {
		super(c.getRed() / 255F, c.getGreen() / 255F, c.getBlue() / 255F);
	}

	/**
	 * Constructs and initializes a Color3f from the specified Color3f.
	 * 
	 * @param c
	 */
	public Color3f(Color3f c) {
		super(c);
	}

	/**
	 * Constructs and initializes a Color3f from the array of length 3.
	 * 
	 * @param c
	 */
	public Color3f(float c[]) {
		super(c);
	}

	/**
	 * Constructs and initializes a Color3f from the three xyz values.
	 * 
	 * @param r
	 * @param g
	 * @param b
	 */
	public Color3f(float r, float g, float b) {
		super(r, g, b);
	}

	/**
	 * Constructs and initializes a Color3f from the specified Tuple3f.
	 * 
	 * @param t
	 */
	public Color3f(Tuple3f t) {
		super(t);
	}

	public Color3f add(Color3f other) {
		return new Color3f(x + other.x, y + other.y, z + other.z);
	}

	public Color3f clamp() {
		return new Color3f(Math.min(1, Math.max(0, this.x)), Math.min(1, Math
				.max(0, this.y)), Math.min(1, Math.max(0, this.z)));
	}

	/**
	 * Returns a new AWT color object initialized with the r,g,b values of this
	 * Color3f object.
	 * 
	 * @return
	 */
	public final Color get() {
		int i = Math.round(x * 255F);
		int j = Math.round(y * 255F);
		int k = Math.round(z * 255F);
		return new Color(i, j, k);
	}

	public Color3f multiply(Color3f other) {
		return new Color3f(this.x * other.x, this.y * other.y, this.z * other.z);
	}

	public Color3f scale(float dot) {
		return new Color3f(x * dot, y * dot, z * dot);
	}

	/**
	 * Sets the r,g,b values of this Color3f object to those of the specified
	 * AWT Color object.
	 * 
	 * @param c
	 */
	public final void set(Color c) {
		x = c.getRed() / 255F;
		y = c.getGreen() / 255F;
		z = c.getBlue() / 255F;
	}
}
